/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.view.systemView;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;

import com.ruipengkj.ApplicationContext;
import com.ruipengkj.commons.util.SwingUtil;
import com.ruipengkj.commons.util.Util;
import com.ruipengkj.view.base.BaseInternalFrame;
import com.ruipengkj.view.memberView.AddUserPanel;

/**
 * 说明：
 * 会员主窗体
 * @Author：李智深
 * @Date：2012-03-15
 * 
 */
public class UserFrame extends BaseInternalFrame{

	private static final long serialVersionUID = 1L;
	
	private JToolBar toolBar;//工具栏
	
	private JPanel main;//主面板
	private CardLayout main_layout;//主面板布局
	
	private JButton adduser;//增加用户
	private JButton selectuser;//浏览用户
	
	//private JButton deleteuser;//删除用户
	//private JButton updateuser;//修改用户
	
	
	//private MemberQueryCardPanel meberQueryCardPanel;//会员卡查询面板
	
	private SelectUserPanel selectUserPanel;//用户查询面板
	
	//private MemberCreateCardPanel menberCreateCardPanel; //发卡面板
	
	
	private AddUserPanel addUserPanel; //发卡面板

	public UserFrame(String title, boolean resizable, boolean closable, boolean maximizable,boolean iconifiable){
		super(title, resizable, closable, maximizable,iconifiable);
		this.init();
	}
	
	private void init(){
		this.setLayout(new BorderLayout());
		this.initViews();
		this.initListener();
	}
	
	//初始化组件
	private void initViews(){
		toolBar = new JToolBar();
		toolBar.setFloatable(false);//设置工具栏不可移动
		adduser=new JButton("增加用户",SwingUtil.getOpenSwingImage("member_card_the issuing.png"));
		selectuser=new JButton("用户查询",SwingUtil.getOpenSwingImage("member_ card_query.png"));
		

		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL21)){
			toolBar.add(adduser);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL23)){
			toolBar.add(selectuser);
		}
//		toolBar.add(paramDisplayButton);
		main=new JPanel();
		main_layout=new CardLayout();
		main.setLayout(main_layout);
		
		this.add(toolBar,BorderLayout.NORTH);
		this.add(main,BorderLayout.CENTER);
	}
	
	//初始化监听器
	private void initListener(){
		adduser.addActionListener(this);
		selectuser.addActionListener(this);
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==adduser){
			//增加用户
			addUserPanel=new AddUserPanel();
			main.add(addUserPanel,"menberCreateCardPanel");
			main_layout.show(main, "menberCreateCardPanel");
			this.setTitle("用户管理--增加");
			Util.setButtonStatus(toolBar,adduser);
		}else if(e.getSource()==selectuser){
			//查询用户
			selectUserPanel=new SelectUserPanel();
			main.add(selectUserPanel,"meberQueryCardPanel");
			main_layout.show(main, "meberQueryCardPanel");
			this.setTitle("用户管理--查询");
			Util.setButtonStatus(toolBar,selectuser);
			SwingUtilities.invokeLater(selectUserPanel);
		}
		main.updateUI();
	}
	
	public void showButton(){
		if (toolBar != null && toolBar.getComponentCount() != 0)
			((JButton)toolBar.getComponent(0)).doClick();
	}
	
	public void showButton(int type){
		switch(type){
			case 1:{adduser.doClick();break;}
			case 2:{selectuser.doClick();break;}
		}
	}
}
